package dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.NumberFormat;
import java.util.ArrayList;

import util.DBUtil;
import bean.Online;

public class touyundeo {
	public ArrayList<Online> getTouyunList(String sql) throws SQLException {
		Connection conn = DBUtil.open();
		Statement stmt = conn.createStatement();
		ResultSet rs = null;
		ArrayList<Online> list = new ArrayList<Online>();
		
		NumberFormat precent = NumberFormat.getPercentInstance();
		precent.setMinimumFractionDigits(0);
		//��д�ٷ���

		try {
			 rs = stmt.executeQuery(sql);
			while (rs.next()) {
				String area=rs.getString(1);
				String company_num = rs.getString(2);
				String monitor_num = rs.getString(3);
				float online_rate = Float.parseFloat(rs.getString(7));
				float yonline_rate = Float.parseFloat(rs.getString(6));
				Online tou = new Online();

				tou.setArea(area);
				tou.setCompany_num(company_num);
				tou.setMonitor_num(monitor_num);
				tou.setOnline_rate(precent.format(online_rate));
				tou.setYonline_rate(precent.format(yonline_rate));
				list.add(tou); 
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
		return list;
	}
}
